home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / Maya_blinn_vertex.cg < prev    next >
Encoding:
Text File  |  2003-07-17  |  2.2 KB  |  75 lines

  1. // phong_vertex.cg
  2. //
  3. // This file cannot be directly compiled through CG... it first must be
  4. // parsed to insert channel-specific instructions.
  5. //
  6.  
  7. struct vert2frag
  8. {
  9.     float4 hPosition            : POSITION;
  10.     float4 wPosition            : TEXCOORD0;
  11.     float3 wBinormal            : TEXCOORD1;
  12.     float4 colorTexUv            : TEXCOORD2;
  13.     float3 wTangent                : TEXCOORD3;
  14.     float4 bumpTexUv            : TEXCOORD4;
  15.     float4 specTexUv            : TEXCOORD5;
  16.     float4 transpTexUv            : TEXCOORD6;
  17. };
  18.  
  19. // define inputs from application
  20. struct app2vert
  21. {
  22.     float4 position             : POSITION;
  23.     float4 normal               : NORMAL;
  24.     float4 colorTexUv            : TEXCOORD0;
  25.     float4 bumpTexUv            : TEXCOORD1;
  26.     float4 specTexUv            : TEXCOORD2;
  27.     float4 tangent                : TEXCOORD3;
  28.     float4 transpTexUv            : TEXCOORD4;
  29. };
  30.  
  31. vert2frag main(app2vert IN, 
  32.                uniform float4x4 modelViewProj,                
  33.                uniform float4x4 objToWorldMatrix)
  34. {
  35.     vert2frag OUT;
  36.  
  37. #ifdef PROFILE_ARBVP1
  38.     modelViewProj = glstate.matrix.mvp;
  39. #endif
  40.  
  41.     // Compute the clip-space vertex position.
  42.     //
  43.     OUT.hPosition = mul(modelViewProj, IN.position);
  44.  
  45.     // Compute the world-space vertex position.
  46.     //
  47.     OUT.wPosition = mul(objToWorldMatrix, IN.position);
  48.  
  49.     // Compute the geometric normal, expressed in world space.
  50.     // Note: we pass in the tangent and binormal vector
  51.     // rather than the normal. Then in the fragment program,
  52.     // we recompute the normal using a cross-product. This ensures
  53.     // that we'll get the correct normal even when the model matrix
  54.     // has non-proportional scale, and it's cheaper than multiplying
  55.     // by the inverse-transpose.
  56.     //
  57.     float3 oNormal = normalize(IN.normal.xyz);
  58.     float3 oBinormal = normalize(cross(oNormal, IN.tangent.xyz));
  59.     float3 oTangent = cross(oBinormal, oNormal);
  60.  
  61.     float3x3 objToWorldRotationMatrix = (float3x3)objToWorldMatrix;
  62.  
  63.     OUT.wTangent = normalize(mul(oTangent, transpose(objToWorldRotationMatrix)));
  64.     OUT.wBinormal = normalize(mul(oBinormal, transpose(objToWorldRotationMatrix)));
  65.  
  66.     // Copy the texture coordinates.
  67.     //
  68.     OUT.colorTexUv = IN.colorTexUv;
  69.     OUT.bumpTexUv = IN.bumpTexUv;
  70.     OUT.specTexUv = IN.specTexUv;
  71.     OUT.transpTexUv = IN.transpTexUv;
  72.  
  73.     return OUT;
  74. }
  75.